class AIManager:
    """AI助手管理器"""

    def __init__(self, max_assistants=100):
        self.assistants = [None] * max_assistants
        self.count = 0

    def add_assistant(self, assistant):
        """添加助手"""
        if self.count >= len(self.assistants):
            print("达到最大助手容量")
            return False
        self.assistants[self.count] = assistant
        self.count += 1
        print(f"助手【{assistant.name}】添加成功！")
        return True

    def remove_assistant_by_id(self, aid):
        """根据ID删除助手"""
        for i in range(self.count):
            if self.assistants[i].id == aid:
                removed = self.assistants[i]
                for j in range(i, self.count - 1):
                    self.assistants[j] = self.assistants[j + 1]
                self.assistants[self.count - 1] = None
                self.count -= 1
                print(f"助手【{removed.name}】已删除。")
                return True
        print(f"未找到ID为{aid}的助手")
        return False

    def find_assistant_by_id(self, aid):
        """根据ID查找助手"""
        for i in range(self.count):
            if self.assistants[i].id == aid:
                return self.assistants[i]
        return None

    def update_assistant(self, aid, attribute, value):
        """根据ID修改助手信息"""
        assistant = self.find_assistant_by_id(aid)
        if not assistant:
            print(f"未找到ID为{aid}的助手")
            return False

        if attribute == "name":
            assistant.name = value
        elif attribute == "type":
            assistant.type = value
        elif attribute == "version":
            assistant.version = value
        elif attribute == "online":
            assistant.is_online = bool(int(value))
        elif attribute == "score":
            assistant.capability_score = float(value)
        else:
            print("不支持的属性")
            return False

        print(f"助手【{aid}】修改成功！")
        return True

    def list_all_assistants(self):
        """列出所有助手"""
        if self.count == 0:
            print("暂无助手")
            return
        print("所有AI助手列表：")
        for i in range(self.count):
            a = self.assistants[i]
            status = "在线" if a.is_online else "离线"
            print(
                f"{i + 1}. ID: {a.id}, 名称: {a.name}, 类型: {a.type}, 版本: {a.version}, 状态: {status}, 能力评分: {a.capability_score}")

    def display_statistics(self):
        """显示系统统计信息"""
        total = self.count
        if total == 0:
            print("系统统计信息：\n总助手数: 0")
            return

        online_count = sum(1 for i in range(total) if self.assistants[i].is_online)
        offline_count = total - online_count
        avg_score = sum(self.assistants[i].capability_score for i in range(total)) / total

        print(
            f"系统统计信息：\n总助手数: {total}\n在线助手数: {online_count}\n离线助手数: {offline_count}\n平均能力评分: {avg_score:.2f}")
